package com.library.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import com.library.bean.User;
import com.library.dao.UserDao;
import com.library.util.DBUtil;

public class UserDaoImpl implements UserDao {

	JdbcTemplate jt = new JdbcTemplate(DBUtil.getDataSource());
	
	@Override
	public User selectUser(String username, String password) {
		String sql = "SELECT * FROM user WHERE username = ? AND password = ?";
		List<User> list = jt.query(sql, new BeanPropertyRowMapper<User>(User.class),username,password);
		if(list.size() == 0) {
			return null;
		}else {
			return list.get(0);
		}
	}

	@Override
	public User selectUser(String username) {
		String sql = "SELECT * FROM user WHERE username = ?";
		List<User> list = jt.query(sql, new BeanPropertyRowMapper<User>(User.class),username);
		if(list.size() == 0) {
			return null;
		}else {
			return list.get(0);
		}
	}
	

}
